﻿using PostSharp.Aspects;
using PostSharp.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Bigger.Study.ConsoleApp.PostSharp
{
    [PSerializable]
    public class MethodAspect1Attribute : OnMethodBoundaryAspect
    {
        public override void OnEntry(MethodExecutionArgs args)
        {
            Arguments arguments = args.Arguments;
            MethodInfo methodInfo = args.Method as MethodInfo;
            object methodExecutionTag = args.MethodExecutionTag;
            object returnValue = args.ReturnValue;
            object yieldValue = args.YieldValue;
            object instance = args.Instance;

            Console.WriteLine("MethodAspect1Attribute.OnEntry(args)");
        }

        public override void OnException(MethodExecutionArgs args)
        {
            Console.WriteLine("MethodAspect1Attribute.OnException(args)");
            //args.FlowBehavior = FlowBehavior.Return;
            //args.ReturnValue = "Exception Return Value";
        }

        public override void OnExit(MethodExecutionArgs args)
        {
            Console.WriteLine("MethodAspect1Attribute.OnExit(args)");
            //Console.WriteLine(args.ReturnValue);
        }

        public override void OnResume(MethodExecutionArgs args)
        {
            Console.WriteLine("MethodAspect1Attribute.OnResume(args)");
        }

        public override void OnSuccess(MethodExecutionArgs args)
        {
            Console.WriteLine("MethodAspect1Attribute.OnSuccess(args)");
        }

        public override void OnYield(MethodExecutionArgs args)
        {
            Console.WriteLine("MethodAspect1Attribute.OnYield(args)");
        }
    }
}
